package org.gl.training.planner.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "user")
public class User {

	@Id
	@Column(name = "Id")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;

	@Column(name = "UserName", length = 45)
	private String userName;

	@Column(name = "FullName", length = 80)
	private String fullName;

	@Column(name = "EMail", length = 45)
	private String email;

	@Column(name = "Password", length = 45)
	private String password;

	@Transient
	private String confirmPassword;

	@Column(name = "Notes", length = 45)
	private String notes;

	@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
	@JoinTable(name = "user_has_user_types", joinColumns = { @JoinColumn(name = "user_Id") }, inverseJoinColumns = { @JoinColumn(name = "user_types_id") })
	private List<UserTypes> userTypesList;

	@Column(name = "UserStatus", length = 45)
	private String userStatus;

	@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private List<UserHistory> userHistoryList;

	@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	private List<DailyPlan> dailyPlanList;

	@Transient
	private boolean selected;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getFullName() {
		return fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	public String getUserStatus() {
		return userStatus;
	}

	public void setUserStatus(String userStatus) {
		this.userStatus = userStatus;
	}

	public List<UserHistory> getUserHistoryList() {
		return userHistoryList;
	}

	public void setUserHistoryList(List<UserHistory> userHistoryList) {
		this.userHistoryList = userHistoryList;
	}

	public List<DailyPlan> getDailyPlanList() {
		return dailyPlanList;
	}

	public void setDailyPlanList(List<DailyPlan> dailyPlanList) {
		this.dailyPlanList = dailyPlanList;
	}

	public String getConfirmPassword() {
		return confirmPassword;
	}

	public void setConfirmPassword(String confirmPassword) {
		this.confirmPassword = confirmPassword;
	}

	public List<UserTypes> getUserTypesList() {
		return userTypesList;
	}

	public void setUserTypesList(List<UserTypes> userTypesList) {
		this.userTypesList = userTypesList;
	}

	public boolean isSelected() {
		return selected;
	}

	public void setSelected(boolean selected) {
		this.selected = selected;
	}

	public boolean isAdmin() {
		for (UserTypes userTypes : userTypesList) {
			if (userTypes.equals(UserTypes.ADMIN)) {
				return true;
			}
		}
		return false;
	}

	public boolean isUser() {
		for (UserTypes userTypes : userTypesList) {
			if (userTypes.equals(UserTypes.USER)) {
				return true;
			}
		}
		return false;
	}
}